@page "{id:min(1)?}/{handler?}"
@model EditModel
@{
    var pageHeader = Model.Student.Id > 0 ? "编辑学生" : "添加学生"; 
    ViewData["Title"] = pageHeader; 

    // 如果学生没有照片信息，就默认给他一张空照片
    var photoPath = "~/images/" + (Model.Student.PhotoPath ?? "noimage.png");
}

 
<div class="row">

    <div class="col-md-12">   
        <h1>消息通知配置开关</h1>
        <form method="post" asp-page-handler="UpdateNotificationPreferences"  >

            <div class="form-check">
                <input asp-for="Notify"  class="form-check-input"/>
               
                <label asp-for="Notify" class="form-check-label">
                    
                    允许接收消息通知信息

                </label>

            </div>


            <button type="submit" class="btn btn-primary">
     
                更新消息通知

            </button>
             

        </form>
    
        <hr/>
        </div>
    

    <div class="col-md-12">
        <h1>@pageHeader</h1>

        <form method="post" class="mt-3" asp-page-handler="OnPost" enctype="multipart/form-data">
            @*使用隐藏的input标签来存储提交表单时需要的学生id*@
            <input hidden asp-for="Student.Id"/>
            <input hidden asp-for="Student.PhotoPath"/>

            <div class="text-danger" asp-validation-summary="All"></div>


            @*asp-for TagHelper 负责在处理在不同的标签中显示现有的数据*@
            <div class="form-group row">
                <label asp-for="Student.Name" class="col-sm-2 col-form-label">
                </label>
                <div class="col-sm-10">
                    <input asp-for="Student.Name" class="form-control" placeholder="Name">
                    <span class="text-danger" asp-validation-for="Student.Name"></span>
                </div>
            </div>
            <div class="form-group row">
                <label asp-for="Student.Email" class="col-sm-2 col-form-label"></label>
                <div class="col-sm-10">
                    <input asp-for="Student.Email" class="form-control" placeholder="Email">
                </div>
            </div>

            <div class="form-group row">
                <label asp-for="Student.Major" class="col-sm-2 col-form-label"></label>
                <div class="col-sm-10">
                    <select asp-for="Student.Major" class="custom-select mr-sm-2"
                            asp-items="Html.GetEnumSelectList<MajorEnum>()">
                        <option value="">请选择</option>


                    </select>
                    <span asp-validation-for="Student.Major" class="text-danger"></span>
                </div>
            </div>





            <div class="form-group row">
                <label asp-for="Photo" class="col-sm-2 col-form-label"></label>
                <div class="col-sm-10">
                    <div class="custom-file">
                        @*Photo属性类型是IFormFile，ASP. NET Core会根据这个属性自动创建一个FileUpload控件 *@
                        @* 有关更具体的信息在《深入浅出ASP.NET Core》那本书有介绍 *@
                        <input asp-for="Photo" class="custom-file-input form-control">
                        <label class="custom-file-label">更换图片</label>
                    </div>
                </div>
            </div>
            @*显示有照片的学生信息*@
            <div class="form-group row col-sm-4 offset-4">
                <img class="imageThumbnail" src="@photoPath" asp-append-version="true"/>
            </div>

            <div class="form-group row">
                <div class="col-sm-10">
                    <button type="submit" class="btn btn-primary">更新</button>
                    <a asp-page="/Students/Index" class="btn btn-primary">取消</a>
                </div>
            </div>
        </form>
    </div>





</div>


@section Scripts {
    
@*  @await  Html.PartialAsync("_ValidationScriptsPartial")*@    
  <partial name="_ValidationScriptsPartial"/>

    <script>
        $(document).ready(function () {

            $('.custom-file-input').on("change", function () {
                var fileName = $(this).val().split("\\").pop();
                $(this).next('.custom-file-label').html(fileName);
            });
        });
    </script>
    
 
}